package com.yin.waimai.controller;

import com.yin.waimai.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/v1/regions")
public class RegionController {

    @Autowired
    private RegionService regionService;

    /**
     * 获取所有省份
     */
    @GetMapping("/provinces")
    public ResponseEntity<?> getAllProvinces() {
        return ResponseEntity.ok(regionService.getAllProvinces());
    }

    /**
     * 根据省份代码获取城市列表
     */
    @GetMapping("/cities/{provinceCode}")
    public ResponseEntity<?> getCitiesByProvince(@PathVariable String provinceCode) {
        return ResponseEntity.ok(regionService.getCitiesByProvince(provinceCode));
    }

    /**
     * 根据城市代码获取区县列表
     */
    @GetMapping("/districts/{cityCode}")
    public ResponseEntity<?> getDistrictsByCity(@PathVariable String cityCode) {
        return ResponseEntity.ok(regionService.getDistrictsByCity(cityCode));
    }
}